import {Component, OnInit} from "@angular/core";
import {Components} from "../constants/constants";
import {ActivatedRoute, Router} from "@angular/router";
import {LogUtil} from "../util/log-util";

@Component({
  selector: 'app-client-auth',
  templateUrl: './client-auth.component.html',
  styleUrls: ['./client-auth.component.css']
})
export class ClientAuthComponent implements OnInit {

  constructor(
    private route : ActivatedRoute,
    private router : Router,
    private logUtil : LogUtil
  ) { }

  ngOnInit() {
    this.dispatch();
  }
  private dispatch(){
    this.route.data.subscribe(
      (data:{redirctUrl:string}) => {
        let redirectUrl = data.redirctUrl;
        this.logUtil.debug("client auth:" +redirectUrl);
        if(null != redirectUrl){
          this.router.navigateByUrl(redirectUrl);
        }else{
          this.router.navigateByUrl(Components.authenComponent);
        }
        return false;
      }
    );
  }
}
